/*
 * ***********************************************************
 * @Project: SCVHDemo
 * @File: MainActivity.java
 * @LastEditTime: 2024/11/17 15:07:42
 * @Author: chadm
 * ***********************************************************
 */

package com.example.host;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    final String TAG = MainActivity.class.getSimpleName();
    final String CLIENT_ONE = "com.example.client1";
    final String CLIENT_TWO = "com.example.client2";
    private SurfaceHostManager surfaceHostManager;

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);

        setContentView(R.layout.activity_main);
        SurfaceView surfaceView = findViewById(R.id.surfaceView);
        surfaceHostManager = SurfaceHostManager.getInstance();
        surfaceHostManager.initSurfaceView(surfaceView);
        surfaceView.setOnTouchListener((v, event) -> {
            Log.i(TAG,"onTouch");
            surfaceHostManager.sendTouchToClient(event);
            return false;
        });

        // 切换不同的视图
        Button client1 = findViewById(R.id.button1);
        client1.setOnClickListener(view -> {
            surfaceHostManager.changeShowView(CLIENT_ONE);
        });
        Button client2 = findViewById(R.id.button2);
        client2.setOnClickListener(view -> {
            surfaceHostManager.changeShowView(CLIENT_TWO);
        });



        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
    }
}